Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Notion's /v1/search API uses exact matching, causing searches like "names to remember" or "old lady at the park" to return zero results when page titles don't match precisely.

Changes

Query variation generation (_generate_search_variations)

  • Decomposes queries into individual significant terms (≥4 chars) and adjacent pairs
  • Filters common noise words ("to", "at", "the", "and")
  • Example: "names to remember"["names to remember", "names", "remember", "names remember"]

Multi-strategy search (_perform_enhanced_search)

  • Tries original query first; if <3 results, attempts variations
  • Deduplicates by page ID, handles API errors gracefully
  • Caps at 4 API calls (1 original + 3 variations), terminates at 5+ results

Updated search tool (notion_search)

  • Transparently integrates enhanced search with no API changes
  • Updated docstring to reflect improved matching behavior

Result

# Before: exact match only
await notion_search("old lady at the park")  # → 0 results

# After: tries variations
await notion_search("old lady at the park")  
# Searches: "old lady at the park" → "lady" → "park" → "lady park"
# → 3-5 results

Test coverage: 7 new tests covering variation generation, enhanced search behavior, error handling, deduplication

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

still not working good, when I search for things to remember it should pull up possible matches but it misses

/home/jack/Backend_FastAPI/logs/conversations/2025-10-28/session_2025-10-28_05-01-07_EDT_88b179e5f1224974b791d209b03f2832.log

[Chronological Review: The conversation began with the user expressing a desire to set up tools for a Notion MCP server to help the LLM remember names and other information. The user then delegated tasks to a cloud agent. The conversation shifted to querying information about Russell's kids, where the assistant successfully retrieved names but failed to find specific details initially. The user questioned why the LLM did not retrieve certain names and expressed frustration with the search functionality, particularly regarding the "old lady at the park." The user continued to report issues with the search tool not pulling up relevant matches.]

[Intent Mapping: The user explicitly requested to set up tools for remembering names and information. They sought to understand why certain queries did not yield expected results and expressed a desire for the LLM to effectively search and retrieve relevant information from their notes.]

[Technical Inventory: Tools mentioned include:

  • notion_search: Used to search for specific queries in Notion.
  • notion_retrieve_page: Used to retrieve detailed information from a specific Notion page.
    The user is working with a Notion MCP server to manage reminders and names.]

[Code Archaeology: The user referenced the file /home/jack/Backend_FastAPI/src/backend/mcp_servers/notion_server.py, indicating recent edits that may affect functionality. Specific functions related to searching and retrieving data from Notion were discussed.]

[Progress Assessment: The user successfully retrieved names related to Russell's kids but encountered issues with the search tool not returning expected results for queries about the "old lady at the park" and other names. The user expressed ongoing frustration with the tool's performance.]

[Context Validation: The conversation captures the user's goals of improving the search functionality of their Notion integration and ensuring that relevant information is easily accessible.]

[Recent Commands Analysis:

  • Last Agent Commands:
    • notion_search: Searched for "old lady at the park."
    • notion_retrieve_page: Attempted to retrieve a page with ID "29896b0b-3790-8169-8fec-f68159bed5a4."
  • Tool Results Summary:
    • notion_search returned no matching pages for "old lady at the park."
    • notion_retrieve_page resulted in a 404 error, indicating the page could not be found.
  • Pre-Summary State: The agent was actively addressing the user's concerns about the search functionality when the token budget was exceeded.
  • Operation Context: The user aimed to enhance the LLM's ability to search and retrieve relevant names and information from their notes, which is crucial for their reminder system.]
1. Conversation Overview: - Primary Objectives: The user requested to set up tools for remembering names and information, stating, "my plan is to set up the tool names and descriptions so that the llm uses them for context about reminders." - Session Context: The conversation involved querying names related to Russell's kids, discussing the effectiveness of the search tool, and expressing frustration over missed matches. - User Intent Evolution: The user shifted from setting up tools to troubleshooting the search functionality, seeking clarity on why certain queries did not yield expected results.
  1. Technical Foundation:
  • Notion MCP Server: The user is integrating a Notion server to manage reminders and names.
  • Tools:
    • notion_search: Used for querying names and information.
    • notion_retrieve_page: Used for retrieving detailed information from Notion pages.
  1. Codebase Status:
  • /home/jack/Backend_FastAPI/src/backend/mcp_servers/notion_server.py: This file has been edited recently, potentially affecting the search functionality.
  • Key Code Segments: Functions related to searching and retrieving data from Notion were discussed.
  1. Problem Resolution:
  • Issues Encountered: The search tool did not return expected results for queries about the "old lady at the park" and other names.
  • Solutions Implemented: The user attempted to troubleshoot the search functionality by querying specific names.
  • Debugging Context: The user expressed ongoing frustration with the tool's performance and its inability to pull up relevant matches.
  1. Progress Tracking:
  • Completed Tasks: The user successfully retrieved names related to Russell's kids.
  • Partially Complete Work: The search functionality remains problematic, with the user still seeking effective retrieval of information.
  • Validated Outcomes: Some names were confirmed as retrievable, but the overall search experience is lacking.
  1. Active Work State:
  • Current Focus: The user was troubleshooting the search functionality of their Notion integra...

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 28, 2025 09:13
Co-authored-by: jck411 <81551487+jck411@users.noreply.github.com>
Co-authored-by: jck411 <81551487+jck411@users.noreply.github.com>
Co-authored-by: jck411 <81551487+jck411@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix search tool to retrieve all relevant matches Fix Notion search missing relevant matches with multi-strategy query expansion Oct 28, 2025
Copilot AI requested a review from jck411 October 28, 2025 09:29
@jck411 jck411 marked this pull request as ready for review October 28, 2025 09:39
Copilot AI review requested due to automatic review settings October 28, 2025 09:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Notion search functionality to handle queries that don't exactly match page titles by implementing a multi-strategy query expansion approach. When exact matches yield insufficient results (<3), the system automatically tries variations of the query (individual significant words, adjacent pairs) to find relevant pages, addressing issues where searches like "names to remember" or "old lady at the park" previously returned zero results.

Key changes:

  • Added query variation generation that decomposes queries into significant terms and combinations
  • Implemented enhanced search that tries multiple query variations when initial results are insufficient
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/backend/mcp_servers/notion_server.py Implements _generate_search_variations() and _perform_enhanced_search() functions, integrates enhanced search into notion_search() tool
tests/test_notion_server.py Adds 7 new test cases covering variation generation, enhanced search behavior, deduplication, and error handling

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Fix enhanced search flow and early return; try multiple query variations and deduplicate results
- Improve search variation generation and limit extra queries
- Increase DEFAULT_SEARCH_BLOCK_LIMIT from 20 to 100
- Surface "PAGE ID" consistently in search headings and page summaries
- Default notion_retrieve_page to include_children=True and clarify PAGE ID vs block ID in docs
- Add/expand MCP tool descriptions for notion_search, notion_retrieve_page, notion_create_page, notion_append_block_children, and notion_update_block
- Misc: whitespace/formatting cleanup and minor docstring refinements
Copilot AI requested a review from jck411 October 28, 2025 09:55
@jck411 jck411 merged commit 1560b2a into master Oct 28, 2025
1 check failed
@jck411 jck411 deleted the copilot/improve-search-functionality branch October 28, 2025 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants